//
//  TotalCell.m
//  BOSS-SOOC
//
//  Created by apple on 16/9/5.
//  Copyright © 2016年 Gcx. All rights reserved.
//
#define normalColor [UIColor colorWithRed:26.0/255 green:151.0/255 blue:233.0/255 alpha:1.0f]


#import "TotalCell.h"
#import "UIView+WHC_AutoLayout.h"
#import "MMLabel.h"
#import "TotalModel.h"

@interface TotalCell()

@property (nonatomic, copy) TotalCellBlock quexi_block;//点击缺席按钮的回调block
@property (nonatomic, copy) TotalCellBlock detail_block;//点击详情按钮的回调block

@end

@implementation TotalCell


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{

    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
    if (self) {
        
        _titleLabel     = [MMLabel new];
        _timeLabel      = [MMLabel new];
        _quexiBtn       = [UIButton new];
        _lookBtn       = [UIButton new];
        
        _titleLabel.numberOfLines = 0;
        _titleLabel.font = NormalFont(42);
        _timeLabel.font = NormalFont(40);
        [_quexiBtn setTitle:@"缺席统计" forState:UIControlStateNormal];
        [_quexiBtn setTitleColor:normalColor forState:UIControlStateNormal];
        _quexiBtn.titleLabel.font = NormalFont(40);
        _quexiBtn.layer.masksToBounds = YES;
        _quexiBtn.layer.cornerRadius = 3;
        _quexiBtn.layer.borderColor = normalColor.CGColor;
        _quexiBtn.layer.borderWidth = 0.5;
        [_quexiBtn addTarget:self action:@selector(quexiClicked:) forControlEvents:UIControlEventTouchUpInside];
        
        [_lookBtn setTitle:@"查看详情" forState:UIControlStateNormal];
        [_lookBtn setTitleColor:normalColor forState:UIControlStateNormal];
        _lookBtn.titleLabel.font = NormalFont(42);
        _lookBtn.layer.masksToBounds = YES;
        _lookBtn.layer.cornerRadius = 3;
        _lookBtn.layer.borderColor = normalColor.CGColor;
        _lookBtn.layer.borderWidth = 0.5;
        [_lookBtn addTarget:self action:@selector(detailClicked:) forControlEvents:UIControlEventTouchUpInside];

        [self.contentView addSubview:_lookBtn];
        [self.contentView addSubview:_quexiBtn];
        [self.contentView addSubview:_timeLabel];
        [self.contentView addSubview:_titleLabel];
        
        
        _titleLabel.whc_LeftSpace(ScaleSize(42))
                    .whc_TopSpace(ScaleSize(63))
                    .whc_RightSpace(ScaleSize(42))
                    .whc_heightAuto();
        
        _timeLabel.whc_LeftSpace(ScaleSize(42))
                    .whc_TopSpaceToView(ScaleSize(63),_titleLabel)
                    .whc_Size(CGSizeMake(88, 38));
        
        
        _lookBtn.whc_RightSpace(ScaleSize(42))
                .whc_TopSpaceToView(ScaleSize(63),_titleLabel)
                .whc_Size(CGSizeMake(88, 38));
        
        _quexiBtn.whc_RightSpaceToView(ScaleSize(25)+88,_lookBtn)
                .whc_TopSpaceToView(ScaleSize(63),_titleLabel)
                .whc_Size(CGSizeMake(88, 38));

    }
    return self;
}

+ (TotalCell *)cellWithTab:(UITableView *)tab{

    static NSString *ident = @"cell";
    
    TotalCell *cell = [tab dequeueReusableCellWithIdentifier:ident];
    
    if (!cell) {
        cell = [[TotalCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ident];
    }
    return cell;
}

- (void)setMyModel:(TotalModel *)myModel{

    _myModel = myModel;
    
    _titleLabel.text = [NSString stringWithFormat:@"%@  (%@)",myModel.kcmc,myModel.skxq];
    
    _titleLabel.textColor = Color333333;
    _titleLabel.keyWord = [NSString stringWithFormat:@"(%@)",myModel.skxq];
    _titleLabel.keyWordColor = Color999999;
    
    _timeLabel.text = [NSString stringWithFormat:@"点名次数：%@",myModel.qdcs];
    
    _timeLabel.textColor = Color333333;
    _timeLabel.keyWord = myModel.qdcs;
    _timeLabel.keyWordColor = [UIColor orangeColor];
}

- (void)quexi:(TotalCellBlock)block{
    _quexi_block = block;
}

- (void)detail:(TotalCellBlock)block{
    _detail_block = block;
}

- (void)quexiClicked:(UIButton *)sender{

    if (self.quexi_block) {
        self.quexi_block(self.myModel);
    }
}

- (void)detailClicked:(UIButton *)sender{
    
    if (self.detail_block) {
        self.detail_block(self.myModel);
    }
}


@end
